
<template tag="以下文档内容为hycli自动生成">
  <el-dialog
    v-model="conf.visible"
    v-if="conf.visible" 
    :title="title"
   :width="conf.width"
    draggable
      align-center="true" 
    :close-on-click-modal="false"
  >
  <el-form :model="form"  ref="form" :rules="rules_aaaqb">
    <el-row>
    <el-col :span="24">
    <!-- {"index":7,"raw":"name","name":"name","cname":"Name","type":{"raw":"varchar2(255)","name":"varchar2","len":255,"dlen":0},"defValue":"","allowNull":false,"constraints":["l","le","c","u","q","v","DN","rows(1)","lw(160)","#like","wf"],"desc":{"raw":"名称","name":"名称"}} -->
    <!--名称 输入控件 -->
    <el-form-item prop="name" label="名称" label-width="100px" label-position="right">
      <el-input clearable style="width: 100%" v-model="form.name"  maxlength="255" 
      :rows="1"  type="textarea" show-word-limit  placeholder="请输入名称"  />
      </el-form-item>
    </el-col>
    <el-col :span="12">
    <!-- {"index":8,"raw":"priority","name":"priority","cname":"Priority","type":{"raw":"number(1)","name":"number","len":1,"dlen":0},"defValue":"0","allowNull":false,"constraints":["l","c","u","v","sl(PRI)","lw(60)","le","tp(radio,c-u)","tp(tag,l)","cidx(102)","uidx(102)"],"desc":{"raw":"优先级","name":"优先级"}} -->
    <el-form-item prop="priority" label="优先级" label-width="100px" label-position="right">
      <el-radio-group v-model="form.priority"   >
        <el-radio-button v-for="item in priorityList" :key="item.value" :label="item.value" >
            {{item.name}}
        </el-radio-button>
      </el-radio-group>
    </el-form-item>
    </el-col>
    <el-col :span="24">
    <!-- {"index":9,"raw":"daily_tp","name":"daily_tp","cname":"DailyTp","type":{"raw":"varchar2(255)","name":"varchar2","len":255,"dlen":0},"defValue":"","allowNull":false,"constraints":["l","le","q","sl","c","u","v","tp(radio,c-u)","tp(multiselect,q)"],"desc":{"raw":"任务类型","name":"任务类型"}} -->
    <el-form-item prop="daily_tp" label="任务类型" label-width="100px" label-position="right">
      <el-radio-group v-model="form.daily_tp"   >
        <el-radio-button v-for="item in daily_tpList" :key="item.value" :label="item.value" >
            {{item.name}}
        </el-radio-button>
      </el-radio-group>
    </el-form-item>
    </el-col>
    <el-col :span="24">
    <!-- {"index":10,"raw":"tsk_reason","name":"tsk_reason","cname":"TskReason","type":{"raw":"varchar2(255)","name":"varchar2","len":255,"dlen":0},"defValue":"","allowNull":false,"constraints":["le","c","q","u","v","rows(1)","#like"],"desc":{"raw":"原因","name":"原因"}} -->
    <!--原因 输入控件 -->
    <el-form-item prop="tsk_reason" label="原因" label-width="100px" label-position="right">
      <el-input clearable style="width: 100%" v-model="form.tsk_reason"  maxlength="255" 
      :rows="1"  type="textarea" show-word-limit  placeholder="请输入原因"  />
      </el-form-item>
    </el-col>
    <el-col :span="24">
    <!-- {"index":11,"raw":"content","name":"content","cname":"Content","type":{"raw":"varchar2(2000)","name":"varchar2","len":2000,"dlen":0},"defValue":"","allowNull":false,"constraints":["le","c","q","u","v","rows(4)","tp(rtext,c-u)","#like"],"desc":{"raw":"内容","name":"内容"}} -->
    <!--内容 输入控件 -->
    <el-form-item prop="content" label="内容" label-width="100px" label-position="right">
      <rtext :html="form.content" :rows="4" @onChange="onRtextcontentChange"></rtext>
    </el-form-item>
    </el-col>
    <el-col :span="24">
    <!-- {"index":12,"raw":"att","name":"att","cname":"Att","type":{"raw":"varchar2(255)","name":"varchar2","len":255,"dlen":0},"defValue":"","allowNull":true,"constraints":["c","u","le","v","rows(1)","tp(link,l-le-v)","tp(file,c-u)"],"desc":{"raw":"附件","name":"附件"}} -->
    <!--附件 文件控件 -->
    <el-form-item prop="att" label="附件" label-width="100px" label-position="right">
      <el-input clearable style="width: 100%" v-model="form.att"  maxlength="255" 
        :rows="1"   show-word-limit 
        placeholder="请输入附件地址或上传文件"  >
        <template #append>
          <el-upload multiple :show-file-list="false" :action="conf.uploadPath" :limit="100" :on-success="onUploadSuccess" >
            <el-button type="primary">选择文件</el-button>
          </el-upload>
        </template>
      </el-input>
    </el-form-item>
    </el-col>
    <el-col :span="24">
    <!-- {"index":13,"raw":"master","name":"master","cname":"Master","type":{"raw":"varchar2(64)","name":"varchar2","len":64,"dlen":0},"defValue":"","allowNull":false,"constraints":["l","le","q","sl(staff_info,-,#lob_id)","q","c","u","v","fq","tp(multicheck,c-u)","lw(120)","tp(multiselect,q)"],"desc":{"raw":"处理人","name":"处理人"}} -->
    <!--处理人 chckbox-group -->
    <el-form-item prop="master" label="处理人" label-width="100px" label-position="right">
      <el-checkbox-group v-model="form.master"  >
      <el-checkbox-button v-for="item in masterList" :key="item.value" :label="item.value"  :value="item.value">
        {{item.name}}
        </el-checkbox-button>
      </el-checkbox-group>
      </el-form-item>
    </el-col>
    <el-col :span="12">
    <!-- {"index":14,"raw":"sponsor","name":"sponsor","cname":"Sponsor","type":{"raw":"varchar2(32)","name":"varchar2","len":32,"dlen":0},"defValue":"","allowNull":false,"constraints":["l","le","c","u","v"],"desc":{"raw":"发起人","name":"发起人"}} -->
    <!--发起人 输入控件 -->
    <el-form-item prop="sponsor" label="发起人" label-width="100px" label-position="right">
      <el-input clearable style="width: 100%" v-model="form.sponsor"  maxlength="32" 
      :rows="0"  placeholder="请输入发起人"  />
      </el-form-item>
    </el-col>
    <el-col :span="12">
    <!-- {"index":15,"raw":"time_span","name":"time_span","cname":"TimeSpan","type":{"raw":"number(10,2)","name":"number","len":10,"dlen":2},"defValue":"","allowNull":false,"constraints":["l","le","c","u","v"],"desc":{"raw":"时长(小时)","name":"时长(小时)"}} -->
    <!--时长(小时) 输入控件 -->
    <el-form-item prop="time_span" label="时长(小时)" label-width="100px" label-position="right">
      <el-input clearable style="width: 100%" v-model="form.time_span"  maxlength="10" 
      :rows="0"  placeholder="请输入时长(小时)"  />
      </el-form-item>
    </el-col>
    <el-col :span="12">
    <!-- {"index":16,"raw":"status","name":"status","cname":"Status","type":{"raw":"number(2)","name":"number","len":2,"dlen":0},"defValue":"","allowNull":false,"constraints":["l","le","sl(dtstatus)","q","c","u","v","tp(radio,c-u)","tp(tag,l)","tp(multiselect,q)"],"desc":{"raw":"状态","name":"状态"}} -->
    <el-form-item prop="status" label="状态" label-width="100px" label-position="right">
      <el-radio-group v-model="form.status"   >
        <el-radio-button v-for="item in statusList" :key="item.value" :label="item.value" >
            {{item.name}}
        </el-radio-button>
      </el-radio-group>
    </el-form-item>
    </el-col>
    <el-col :span="12">
    <!-- {"index":20,"raw":"deal_time","name":"deal_time","cname":"DealTime","type":{"raw":"date","name":"date","len":0,"dlen":0},"defValue":"","allowNull":false,"constraints":["l","le","c","u","q","tp(daterange,q)","f(MM/dd)","tp(date,c-u,yyyy/MM/dd)","v"],"desc":{"raw":"处理时间","name":"处理时间"}} -->
    <!--处理时间 日期控件 -->
    <el-form-item prop="deal_time" label="处理时间" label-width="100px" label-position="right">
      <el-date-picker style="width: 100%" v-model="form.deal_time" clearable type="date"
          placeholder="请选择处理时间" format="YYYY-MM-DD" value-format="YYYY-MM-DD"  :default-time="new Date($theia.str.dateFormat(new Date(),'yyyy/MM/dd'))"/>
    </el-form-item>
    </el-col>
    </el-row>
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="hide" icon="close">取消</el-button>
        <el-button type="primary" @click="save" icon="select">提交</el-button>
      </span>
    </template>
  </el-dialog>
</template>

<script>
import rtext from "@/views/cmpnts/rtext.vue"
export default {
  components: {
    rtext
},
  data() {
    return {
      conf: {
        title:"添加日常事务",
        visible: false,
        width:"70%",
        uploadPath:this.$theia.env.join("/file/upload"),
      },
rules_aaaqb:{
    name:[{required:true,message:"请输入名称",trigger: 'blur'}],
    priority:[{required:true,message:"请输入优先级",trigger: 'blur'}],
    daily_tp:[{required:true,message:"请输入任务类型",trigger: 'blur'}],
    tsk_reason:[{required:true,message:"请输入原因",trigger: 'blur'}],
    content:[{required:true,message:"请输入内容",trigger: 'blur'}],
    att:[{required:false,message:"请输入附件",trigger: 'blur'}],
    master:[{required:true,message:"请输入处理人",trigger: 'blur'}],
    sponsor:[{required:true,message:"请输入发起人",trigger: 'blur'}],
    time_span:[{required:true,message:"请输入时长(小时)",trigger: 'blur'}],
    status:[{required:true,message:"请输入状态",trigger: 'blur'}],
    deal_time:[{required:true,message:"请输入处理时间",trigger: 'blur'}],
  },
    form:{
        name:"",
        priority:"",
        daily_tp:"",
        tsk_reason:"",
        content:"",
        att:"",
        master:[],
        sponsor:"",
        time_span:"",
        status:"",
        deal_time:"",
    },
    priorityList:[],
    daily_tpList:[],
    masterList:[],
    statusList:[],
    }
  },
  methods: {
    show(fm = {}) {
      this.title = fm.$title || this.title
      this.conf.visible = true;
      this.loadEnums_aaaqb()
      let local = {}
      let cache = Object.assign(local,fm)
      this.form = Object.assign(cache,this.$route.params)
    },
    save(){
      this.$refs.form.validate((v=>{
          if(v) this.onSave()
      }))
    },
    onSave(){
        let that = this
        let postForm = Object.assign({},this.form)
        postForm.master = (postForm.master||[]).join(",")
        postForm.lob_id = this.$theia.user.get("lob_id")
        //保存数据
        this.$theia.http.post("/ws/daily/task",postForm).then(res=>{
            that.$notify.success({title: '成功',message: '日常事务保存成功',duration:5000})
            that.hide()
            that.$theia.enum.clear("daily_task")
            that.$emit("onsaved")
        }).catch(res=>{
            let code = ((res||{}).response||{}).status||0
            let msg= `日常事务保存失败(${code})`
            msg = code == 909? msg+"数据重复，请修改后重试":msg
            that.$notify.error({title: '失败',message:msg,duration:5000})
        })
    },
    hide() {
      this.conf.visible = false;
      this.$refs.form.resetFields();
    },
    onRtextcontentChange(text,urls){
      this.form.content = text
      this.form.content_urls = (urls||[]).join(",")
    },
    onUploadSuccess(response){
      this.form.att = response.path
    },
    loadEnums_aaaqb(){
        //优先级
        this.priorityList = this.$theia.enum.get("PRI","","" ,false,"")
        //任务类型
        this.daily_tpList = this.$theia.enum.get("daily_tp","","" ,false,"")
        //处理人
        this.masterList = this.$theia.enum.get("staff_info","",this.$theia.user.get("lob_id"),false,"")
        //状态
        this.statusList = this.$theia.enum.get("dtstatus","","" ,false,"")
    },

},
}
</script>

<style scoped>
.avatar-uploader .avatar {
  width: 80px;
  height: 80px;
  display: block;
}
.form_item_info{
  margin-left: 4px;
  color:#999;
}
.form_item_info:hover{
  cursor: pointer;
  font-weight: 500;
  color:#333;
}
</style>